package com.ltsznh.android.frequencycounter;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.shapes.Shape;
import android.util.Log;
import android.view.SurfaceHolder;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by 涛 on 13-12-24.
 */
public class TouchThread extends Thread {
    private final SurfaceHolder compassSH;
    private Paint cPaint = new Paint();
    private Canvas canvas;

    private Paint clearPaint = new Paint();

    private int cWidth = 0;
    private int cHeight = 0;
    private float cX = 0;
    private float cY = 0;
    private float cR = 0;
    private double zR = 0.85;

    int ii = -1;

    public TouchThread(SurfaceHolder surfaceHolder) {
        // TODO Auto-generated constructor stub
        compassSH = surfaceHolder;

        cPaint.setColor(Color.rgb(0, 221, 255));
        cPaint.setAntiAlias(true);//锯齿效果
        cPaint.setStyle(Paint.Style.STROKE);//设置空心
        cPaint.setStrokeWidth(1);//线条粗细



    }

    protected void setSize(int x,int y){
        cWidth = x;
        cHeight = y;

        cX = cWidth/2;
        cY = cHeight/2;
        cR = Math.max(cX, cY);


    }

    public void run(){
        try {
//            for(int i = 0;i < cR;i+=100){
//                drawItem();
//            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    protected void drawCircle(){

        if(cR<0){
            ii=ii*-1;

        }
        cR = cR + 1*ii;
        drawItem();
    }


    public void drawItem(){
//        canvas = compassSH.lockCanvas(new Rect(0,0,cWidth,cHeight));
        canvas = compassSH.lockCanvas();
        try {
            synchronized (compassSH) {
                Log.v("dddd","drawItem" + cR);
                canvas.drawRect(0,0,cWidth,cHeight,clearPaint);

                canvas.drawCircle(cX, cY, cR, cPaint);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (canvas != null) {
                compassSH.unlockCanvasAndPost(canvas);
            }
        }


    }
}
